//
//  FriendTableViewCell.m
//  YMIM
//
//  Created by admin on 2022/3/23.
//

#import "FriendTableViewCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import <MJExtension/MJExtension.h>
@implementation FriendTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
     
        [self initview];
    }
    
    return self;
}
-(void)setFriendInfo:(YMFriendInfo *)friendInfo{
    
    NSString *userAvatar =friendInfo.friendAvatar?:@"";
    NSString *username = friendInfo.friendName?:@"";
    if ([friendInfo.friendAvatar isEqual:[NSNull null]]) {
        
    }else{
        
        [self.headImageView sd_setImageWithURL:[NSURL URLWithString:userAvatar]];
    }
    self.nameLable.text = username;
   
}
-(void)initview{
    
    [self.contentView addSubview:self.nameLable];
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.addButton];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.left.mas_lessThanOrEqualTo(self.contentView.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    [self.nameLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.headImageView.mas_right).offset(10);
        make.centerY.mas_equalTo(self.headImageView.mas_centerY);
        
    }];
    
    [self.addButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.right.mas_lessThanOrEqualTo(self.contentView.mas_right).offset(-20);
        make.size.mas_equalTo(CGSizeMake(70, 30));
    }];
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(UIImageView *)headImageView{
    
    if (_headImageView == nil) {
        
        _headImageView = [[UIImageView alloc]init];
//        _headImageView.backgroundColor = [UIColor orangeColor];
        _headImageView.layer.cornerRadius = 22.5;
        _headImageView.clipsToBounds = YES;
    }
    
    return _headImageView;
}
-(UILabel *)nameLable{
    
    if (_nameLable == nil) {
    
        _nameLable = [[UILabel alloc]init];
        _nameLable.text = @"我是昵称";
        _nameLable.textColor = [UIColor blackColor];
        _nameLable.font = [UIFont systemFontOfSize:16];
    }
    return _nameLable;
}
-(UIButton *)addButton{
    
    if (_addButton == nil) {
        
        _addButton = [[UIButton alloc]init];
         [_addButton setTitle:@"添加好友" forState:UIControlStateNormal];
        [_addButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _addButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _addButton.layer.cornerRadius = 7;
        _addButton.layer.masksToBounds = YES;
        _addButton.backgroundColor = [UIColor colorWithRed:72/255.0 green:142/255.0 blue:255/255.0 alpha:1];
    }
    return _addButton;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
